home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
system
/
devlod.zip
/
DEVLOD.FIG
< prev
next >
Wrap
Text File
|
1990-12-06
|
27KB
|
839 lines
Figure 1: Basic Structure of DEVLOD
startup code (C0.ASM)
main (DEVLOD.C)
Move_Loader
movup (MOVUP.ASM)
Load_Drvr
INT 21h Function 4B03h (Load Overlay)
Get_List
INT 21h Function 52h (Get List of Lists)
based on DOS version number:
get number of block devices
get value of LASTDRIVE
get Current Directory Structure (CDS) base
get pointer to NUL device
Init_Drvr
call DD init routine
build command packet
call Strategy
call Interrupt
Get_Out
if block device:
Put_Blk_Dev
for each unit:
Next_Drive
get next available drive letter
INT 21h Function 32h (Get DPB)
INT 21h Function 53h (Translate BPB -> DPB)
poke CDS
link into DPB chain
Fix_DOS_Chain
link into dev chain
release environment space
INT 21h Function 31h (TSR)
-----------------------------------------------------------------------------
Figure 2: Loading Device Drivers
C:\UNDOC\KYLE>devlod \dos\smartdrv.sys 256 /a
Microsoft SMARTDrive Disk Cache version 3.03
Cache size: 256K in Expanded Memory
Room for 30 tracks of 17 sectors each
Minimum cache size will be 0K
C:\UNDOC\KYLE>devlod \dos\ramdrive.sys
Microsoft RAMDrive version 3.04 virtual disk D:
Disk size: 64k
Sector size: 512 bytes
Allocation unit: 1 sectors
Directory entries: 64
C:\UNDOC\KYLE>devlod \dos\vdisk.sys
VDISK Version 3.2 virtual disk E:
Buffer size adjusted
Sector size adjusted
Directory entries adjusted
Buffer size: 64 KB
Sector size: 128
Directory entries: 64
C:\UNDOC\KYLE>devlod \dos\ansi.sys
C:\UNDOC\KYLE>mem
Seg Owner Size Env
09F3 0008 00F4 ( 3904) config [15 2F 4B 67 ]
0AE8 0AE9 00D3 ( 3376) 0BC1 c:\dos33\command.com [22 23 24 2E ]
0BBC 0000 0003 ( 48) free
0BC0 0AE9 0019 ( 400)
0BDA 0AE9 0004 ( 64)
0BDF 3074 000D ( 208)
0BED 0000 0000 ( 0) free
0BEE 0BEF 0367 ( 13936) 0BE0 \msc\bin\smartdrv.sys 256 /a [13 19 ]
0F56 0F57 1059 ( 66960) 0BE0 \msc\bin\ramdrive.sys [F1 FA ]
1FB0 1FB1 104C ( 66752) 0BE0 \dos33\vdisk.sys
2FFD 2FFE 0075 ( 1872) 0BE0 \dos33\ansi.sys [1B 29 ]
3073 3074 1218 ( 74112) 0BE0 C:\UNDOC\KYLE\MEM.EXE [00 ]
428C 0000 7573 (481072) free [30 F8 ]
C:\UNDOC\KYLE>dev
NUL
CON
Block: 1 unit(s)
Block: 1 unit(s)
SMARTAAR
QEMM386$
EMMXXXX0
CON
AUX
PRN
CLOCK$
Block: 3 unit(s)
COM1
LPT1
LPT2
LPT3
COM2
COM3
COM4
-----------------------------------------------------------------------------
Sidebar
Some DOS and BIOS Data Structures
BPB BIOS uses the BPB (Bios Parameter Block) to learn the format of a
block device. Normally, the BPB is part of a physical disk's boot
record, and contains information such as the number of bytes
in a sector, the number of root directory entries, the number of
sectors taken by the File Allocation Table (FAT), etc.
CDS The CDS (Current Directory Structure) is an undocumented array of
structures, sometimes also called the Drive Info Table, which
maintains the current state of each drive in the system. The array is
n elements long, where n equals LASTDRIVE.
DPB For every block device (disk drive) in the system, there is a DPB
(Drive Parameter Block). These 32-byte blocks contain the information
that DOS uses to convert cluster numbers into Logical Sector Numbers,
and also associate the device driver for that device with its
assigned drive letter.
LoL Probably the most commonly used undocumented DOS data structure,
the List of Lists is the DOS internal variable table, which includes,
amongst other things, the LASTDRIVE value, the head of the device
driver chain, and the CDS (Current Directory Structure). A pointer to
the LoL is returned in ES:BX by undocumented DOS Int 21h Function
52h.
----------------------------------------------------------------------------
Listing 1
/********************************************************************
* DEVLOD.C - Jim Kyle - 08/20/90 *
* Copyright 1990 by Jim Kyle - All Rights Reserved *
* (minor revisions by Andrew Schulman - 9/12/90 *
* Dynamic loader for device drivers *
* Requires Turbo C; see DEVLOD.MAK also for ASM helpers.*
********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
typedef unsigned char BYTE;
#define GETFLAGS __emit__(0x9F) /* if any error, quit right now */
#define FIXDS __emit__(0x16,0x1F)/* PUSH SS, POP DS */
#define PUSH_BP __emit__(0x55)
#define POP_BP __emit__(0x5D)
unsigned _stklen = 0x200;
unsigned _heaplen = 0;
char FileName[65]; /* filename global buffer */
char * dvrarg; /* points to char after name in cmdline buffer */
unsigned movsize; /* number of bytes to be moved up for driver */
void (far * driver)(); /* used as pointer to call driver code */
void far * drvptr; /* holds pointer to device driver */
void far * nuldrvr; /* additional driver pointers */
void far * nxtdrvr;
BYTE far * nblkdrs; /* points to block device count in List of Lists*/
unsigned lastdrive; /* value of LASTDRIVE in List of Lists */
BYTE far * CDSbase; /* base of Current Dir Structure */
int CDSsize; /* size of CDS element */
unsigned nulseg; /* hold parts of ListOfLists pointer */
unsigned nulofs;
unsigned LoLofs;
#pragma pack(1)
struct packet{ /* device driver's command packet */
BYTE hdrlen;
BYTE unit;
BYTE command; /* 0 to initialize */
unsigned status; /* 0x8000 is error */
BYTE reserv[8];
BYTE nunits;
unsigned brkofs; /* break adr on return */
unsigned brkseg; /* break seg on return */
unsigned inpofs; /* SI on input */
unsigned inpseg; /* _psp on input */
BYTE NextDrv; /* next available drive */
} CmdPkt;
typedef struct { /* Current Directory Structure (CDS) */
BYTE path[0x43];
unsigned flags;
void far *dpb;
unsigned start_cluster;
unsigned long ffff;
unsigned slash_offset; /* offset of '\' in current path field */
// next for DOS4+ only
BYTE unknown;
void far *ifs;
unsigned unknown2;
} CDS;
extern unsigned _psp; /* established by startup code in c0 */
extern unsigned _heaptop; /* established by startup code in c0 */
extern BYTE _osmajor; /* established by startup code */
extern BYTE _osminor; /* established by startup code */
void _exit( int ); /* established by startup code in c0 */
void abort( void ); /* established by startup code in c0 */
void movup( char far *, char far *, int ); /* in MOVUP.ASM file */
void copyptr( void far *src, void far *dst ); /* in MOVUP.ASM file */
void exit(int c) /* called by startup code's sequence */
{ _exit(c);}
int Get_Driver_Name ( void )
{ char *nameptr;
int i, j, cmdlinesz;
nameptr = (char *)0x80; /* check command line for driver name */
cmdlinesz = (unsigned)*nameptr++;
if (cmdlinesz < 1) /* if nothing there, return FALSE */
return 0;
for (i=0; i<cmdlinesz && nameptr[i]<'!'; i++) /* skip blanks */
;
dvrarg = (ch